<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Catalog
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


/**
 * Catalog navigation
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author      Magento Core Team <core@magentocommerce.com>
 */

class Verz_Home_Block_Catalog_Navigation extends Mage_Catalog_Block_Navigation
{
    
    public function getLevelOneCategories(){
        
        
        $activeCategories = array();
        
        foreach ($this->getStoreCategories() as $child) {
            if ($child->getIsActive()) {
                $activeCategories[] = $child;
        
            }
        }
        
        return $activeCategories;  
    }
    
    public function getChildrenCategories($category){
        
        
        if(empty($category))
            return false;
        $children = $category->getChildren();
        
        $childrenCount = $children->count();

        $has_category  = ($children && $childrenCount);

        if(!empty($has_category)){    
            return $children;
        }
        return false;
        
    }
    public function getChildrenCategoriesVersionTwo($category_id, $is_view_all=false){
        
        $collection = Mage::getModel('catalog/category')->getCollection();
        /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        
        $collection->addAttributeToSelect('name')
            ->addAttributeToSelect('description')
            ->addAttributeToSelect('image')
            ->addAttributeToSelect('is_active')
            ->addAttributeToSelect('url_key')
            ->addAttributeToSelect('parent_id')
                
            ->addAttributeToFilter('parent_id',$category_id)   
            ->addIsActiveFilter();
        if($is_view_all==false){
            $collection->setPage(0, DEFAULT_NUMBER_HP_BRAND);
        }
        
        /*        
        if ($sorted) {
            if (is_string($sorted)) {
                // $sorted is supposed to be attribute name
                $collection->addAttributeToSort($sorted);
            } else {
                $collection->addAttributeToSort('name');
            }
        }
        */
        return $collection;
    }
    public function getBandList($page){
        
        $collection = Mage::getModel('catalog/category')->getCollection();
        /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        
        $collection->addAttributeToSelect('name')
            ->addAttributeToSelect('description')
            ->addAttributeToSelect('image')
            ->addAttributeToSelect('is_active')
            ->addAttributeToSelect('url_key')
            ->addAttributeToSelect('parent_id')
                
            ->addAttributeToFilter('parent_id',BOTIQUES_CATEGORY_ID)   
            ->addIsActiveFilter();
        
        
         $collection->setPage($page, DEFAULT_LIMIT_BRAND_LIST);
         
         return $collection;
        
    }
    public function countBrandList(){
        
        $collection = Mage::getModel('catalog/category')->getCollection();
        /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        
        $total = $collection->addAttributeToSelect('count(*)')
           
            ->addAttributeToFilter('parent_id',BOTIQUES_CATEGORY_ID)   
            ->addIsActiveFilter()->getSize();
        
        return $total;
    }
    public function getPaginationBrand($page_number){
        
        $total = $this->countBrandList();
        $last = ceil($total/DEFAULT_LIMIT_BRAND_LIST); 
        //this makes sure the page number isn't below one, or more than our maximum pages 
        if ($page_number < 1) 
        { 
            $page_number = 1; 
        } 
        elseif ($page_number > $last) 
        { 
            $page_number = $last; 
        } 
        //This sets the range to display in our query 
        return array("total"=>$total,
                     "page_number"=>$page_number,
                     "last"=>$last,
                     "from"=>($page_number - 1) * DEFAULT_LIMIT_BRAND_LIST,
                     "to"=>$page_number * DEFAULT_LIMIT_BRAND_LIST
                    );
        
   }
   public function getMenus(){
       
       return array("home","mix","update","women","kids","men");
   }
}
